# This script loads the data for the OMI study

# respondent-level data
omi_resp <- read_rds("Data/omi_resp_data.rds")

# recode presidential approval, create variables indicating usage of/trust in
# state media or independent media more generally
omi_resp <- omi_resp |>
  mutate(pres_approval_cat = case_when(
    pres_approval == 1 ~ "Certainly disapprove",
    pres_approval == 2 ~ "Somewhat disapprove",
    pres_approval == 3 ~ "Somewhat approve",
    pres_approval == 4 ~ "Certainly approve"
  ),
  pres_approval_dummy = case_when(
    pres_approval %in% 1:2 ~ 0,
    pres_approval %in% 3:4 ~ 1
  ),
  pres_approval_cat = factor(pres_approval_cat, 
                             levels = c("Certainly disapprove", 
                                        "Somewhat disapprove",
                                        "Somewhat approve", 
                                        "Certainly approve")),
  # whether the respondent uses any state-controlled news sources
  source_used_state_controlled = case_when(
    source_used_Russia_1_24 == 1 | source_used_Vesti == 1 | 
      source_used_TV1 == 1 | source_used_TASS == 1 | 
      source_used_Lenta == 1 | source_used_NTV == 1 | 
      source_used_Gazeta == 1 | source_used_Zvezda == 1 |
      source_used_RIA == 1 | source_used_Izvestiya == 1 |
      source_used_RenTV == 1 | source_used_RT == 1 | 
      source_used_Vzglyad == 1 | source_used_RG == 1 | 
      source_used_KP == 1 | source_used_MK == 1 ~ 1,
    source_used_Russia_1_24 == 0 & source_used_Vesti == 0 & 
      source_used_TV1 == 0 & source_used_TASS == 0 & 
      source_used_Lenta == 0 & source_used_NTV == 0 & 
      source_used_Gazeta == 0 & source_used_Zvezda == 0 &
      source_used_RIA == 0 & source_used_Izvestiya == 0 &
      source_used_RenTV == 0 & source_used_RT == 0 & 
      source_used_Vzglyad == 0 & source_used_RG == 0 & 
      source_used_KP == 0 & source_used_MK == 0 ~ 0
  ),
  # whether the respondent uses any state TV channels
  source_used_state_tv = case_when(
    source_used_Russia_1_24 == 1 | source_used_Vesti == 1 | 
      source_used_TV1 == 1 | source_used_Zvezda == 1 ~ 1,
    source_used_Russia_1_24 == 0 & source_used_Vesti == 0 & 
      source_used_TV1 == 0 & source_used_Zvezda == 0 ~ 0
  ),
  # whether the respondent uses any independent news sources
  source_used_independent = case_when(
    source_used_Rain == 1 | source_used_BBC == 1 | 
      source_used_Echo == 1 | 
      source_used_Meduza == 1 | source_used_Novaya_Gazeta == 1 |
      source_used_Vedomosti == 1 | source_used_Rosbalt == 1 | 
      source_used_foreign == 1 | source_used_Euronews == 1 ~ 1,
    source_used_Rain == 0 & source_used_BBC == 0 & 
      source_used_Echo == 0 & 
      source_used_Meduza == 0 & source_used_Novaya_Gazeta == 0 &
      source_used_Vedomosti == 0 & source_used_Rosbalt == 0 & 
      source_used_foreign == 0 & source_used_Euronews == 0 ~ 0
  ),
  # whether the respondent knows any independent news sources
  source_known_independent = case_when(
    source_known_Rain == 1 | source_known_BBC == 1 | 
      source_known_Echo == 1 | 
      source_known_Meduza == 1 | source_known_Novaya_Gazeta == 1 |
      source_known_Vedomosti == 1 | source_known_Rosbalt == 1 ~ 1,
    source_known_Rain == 0 & source_known_BBC == 0 & 
      source_known_Echo == 0 & 
      source_known_Meduza == 0 & source_known_Novaya_Gazeta == 0 &
      source_known_Vedomosti == 0 & source_known_Rosbalt == 0 ~ 0
  ),
  source_known_independent = case_when(
    source_used_BBC == 1 | source_used_Euronews == 1 |
      source_used_Echo == 1 ~ 1,
    TRUE ~ source_known_independent
  ),
  source_known_independent = case_when(
    source_trusted_Euronews == 1 | source_trusted_foreign == 1 |
      source_trusted_Forbes == 1 | source_trusted_Navalny == 1 ~ 1,
    TRUE ~ source_known_independent
  ),
  # whether the respondent trusts any state-controlled news sources
  source_trusted_state_controlled = case_when(
    source_trusted_Russia_1_24 == 1 | source_trusted_Vesti == 1 | 
      source_trusted_TV1 == 1 | source_trusted_TASS == 1 | 
      source_trusted_Lenta == 1 | source_trusted_NTV == 1 | 
      source_trusted_RIA == 1 | source_trusted_Izvestiya == 1 |
      source_trusted_RenTV == 1 | source_trusted_RT == 1 | 
      source_trusted_Vzglyad == 1 | source_trusted_RG == 1 | 
      source_trusted_KP == 1 | source_trusted_RFAN == 1 |
      source_trusted_Tsargrad == 1 | source_used_MK == 1 ~ 1,
    source_trusted_Russia_1_24 == 0 & source_trusted_Vesti == 0 & 
      source_trusted_TV1 == 0 & source_trusted_TASS == 0 & 
      source_trusted_Lenta == 0 & source_trusted_NTV == 0 & 
      source_trusted_RIA == 0 & source_trusted_Izvestiya == 0 &
      source_trusted_RenTV == 0 & source_trusted_RT == 0 & 
      source_trusted_Vzglyad == 0 & source_trusted_RG == 0 & 
      source_trusted_KP == 0 & source_trusted_RFAN == 0 &
      source_trusted_Tsargrad == 0 & source_used_MK == 0 ~ 0
  ),
  # whether the respondent trusts any state TV channels
  source_trusted_state_tv = case_when(
    source_trusted_Russia_1_24 == 1 | source_trusted_Vesti == 1 | 
      source_trusted_TV1 == 1 ~ 1,
    source_trusted_Russia_1_24 == 0 & source_trusted_Vesti == 0 & 
      source_trusted_TV1 == 0 ~ 0
  ),
  # whether the respondent trusts any independent news sources
  source_trusted_independent = case_when(
    source_trusted_Rain == 1 | source_trusted_BBC == 1 | 
      source_trusted_Echo == 1 | 
      source_trusted_Meduza == 1 | source_trusted_Novaya_Gazeta == 1 |
      source_trusted_Vedomosti == 1 | source_trusted_Rosbalt == 1 |
      source_trusted_Euronews == 1 | source_trusted_foreign == 1 |
      source_trusted_Forbes == 1 | source_trusted_Navalny == 1 ~ 1,
    source_trusted_Rain == 0 & source_trusted_BBC == 0 & 
      source_trusted_Echo == 0 & 
      source_trusted_Meduza == 0 & source_trusted_Novaya_Gazeta == 0 &
      source_trusted_Vedomosti == 0 & source_trusted_Rosbalt == 0 &
      source_trusted_Euronews == 0 & source_trusted_foreign == 0 &
      source_trusted_Forbes == 0 & source_trusted_Navalny == 0 ~ 0
  ))

# load data on story evaluations, join with respondent-level data
omi_stories <- read_rds("Data/omi_stories_data.rds") |>
  left_join(omi_resp) 

